<template>
  <div class="forgetPassword_container pl-1 pr-1">
		<div class="emailLogin_container_card padding-1">
				<p class="mb-0">{{$t("邮箱地址")}}</p>
				<input class="mb-0" type="text" v-model="email">
				<p class="mb-0">{{$t("验证码")}}</p>
				<div class="card_code mb-0">
					<input class="mb-0" type="text" v-model="code">
					<span @click="sendCode">{{$t("发送")}}</span>
				</div>
				<p class="mb-0">{{$t("新密码")}}</p>
				<input class="mb-0" type="password" v-model="newPassword">
				<p class="mb-0">{{$t("确认密码")}}</p>
				<input class="mb-2" type="password" v-model="confirmPassword">
				<button @click="nextClick">{{$t("确认")}}</button>
		</div>
	</div>
</template>

<script>
import { sendCodeToEmail , loginByEmailForget } from '@/request/login'
export default {
	name: 'ForgetPassword',
	data(){
		return {
			email: '',
			code: '',
			newPassword: '',
			confirmPassword: '',
		}
	},
	mounted(){

	},
	methods:{
		nextClick(){
			// 验证验证码
			if(this.email ===''){
				this.$toast.fail(this.$t("请输入邮箱"))
			}else if(this.code ===''){
				this.$toast.fail(this.$t("请输入验证码"))
			}else if(this.newPassword ===''){
				this.$toast.fail(this.$t("请输入新密码"))
			}else if(this.confirmPassword ===''){
				this.$toast.fail(this.$t("请输入确认密码"))
			}else if(this.newPassword !== this.confirmPassword){
				this.$toast.fail(this.$t("两次密码不一致"))
			}else{
				let obj = {
					email:this.email,
					captcha:this.code,
					type:'email',
					newpassword:this.newPassword,
				}
				loginByEmailForget(obj).then(res=>{
					if(res.code === 1){
						this.$toast.success(this.$t("重置密码成功"))
						this.$router.push({name:'EmailLogin'})
					}
				})
			}
		},
		sendCode(){
			// 发送验证码
			if(this.email ===''){
				this.$toast.fail(this.$t("请输入邮箱"))
			}else{
				let obj = {
					email:this.email,
					event:'resetpwd'
				}
				sendCodeToEmail(obj).then(res=>{
					if(res.code === 1){
						this.$toast.success(this.$t("验证码发送成功"))
					}
				})
			}
		},
	}
}
</script>

<style>

</style>